package mahi.collection;

public class Name implements Comparable<Name>{
	String firstName;
	String lastName;
	int age;
	
	public Name(String s1, String s2, int age1) {
		firstName = s1;
		lastName =s2;
		this.age = age1;
	}
	
	
	// if two objects are equal their hashcode will be same
	// if two objects are not equal their hashcode msame
	@Override
	public boolean equals(Object o) {
		if (!(o instanceof Name))
            return false;
        Name n = (Name) o;
        return n.firstName.equals(firstName) && n.lastName.equals(lastName);
	}
	
	@Override
	public int hashCode() {
		 return 31*firstName.hashCode() + lastName.hashCode();
	}
	
	 public String toString() {
			return firstName + " " + lastName;
	}

	@Override
	public int compareTo(Name n) {
		   int lastCmp = lastName.compareTo(n.lastName);
	        return (lastCmp != 0 ? lastCmp : firstName.compareTo(n.firstName));
	}
	 
	
}
